<!DOCTYPE html> 
<html> 
<head> 
	<title>Page Title</title> 
	
	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	<script src="cordova.js"></script>
	<link rel="stylesheet" href="js/jquery.mobile-1.3.1.min.css" />
	<script src="js/jquery-1.10.2.min.js"></script>
	<script src="js/jquery.mobile-1.3.1.min.js"></script>
	<script src="js/filedownload.js"></script>
<script>
     function onLoad(){

          document.addEventListener("deviceready",
onDeviceReady, false);
	
	}

     function onDeviceReady(){
    var db = window.openDatabase("test", "1.0", "Test DB", 1000000);
     db.transaction(populateDB, errorCB, successCB);
     //navigator.splashscreen.hide();
     cordova.exec(null, null, "SplashScreen", "hide", []);
//navigator.notification.alert("PhoneGap is working!!");

	checkConnection();	
	
	
	}
		
	
 //create table and insert some record
    function populateDB(tx) {
         tx.executeSql('DROP TABLE IF EXISTS DEMO');
         tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
         tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
         tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
         tx.executeSql('INSERT INTO DEMO (id, data) VALUES (3, "Third row")');
    }
 
    //function will be called when an error occurred
    function errorCB(tx, err) {
        alert("Error processing SQL: "+err);
    }

    // Transaction success callback
    //
    function successCB() {
        alert("success!");
         var db = window.openDatabase("test", "1.0", "Test DB", 1000000);
        db.transaction(queryDB, errorCB);
        
        
    }
	
	
    // Query the database
    //
    function queryDB(tx) {
        tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
    }

    // Query the success callback
    //
    function querySuccess(tx, results) {
  console.log("Returned rows = " + results.rows.length);
  // this will be true since it was a select statement and so rowsAffected was 0
  if (!results.rowsAffected) {
    console.log('No rows affected!');
    return false;
  }
  // for an insert statement, this property will return the ID of the last inserted row
  console.log("Last inserted row ID = " + results.insertId);
    }
	
 
	function checkConnection() {
            var networkState = navigator.connection.type;

            var states = {};
            states[Connection.UNKNOWN]  = 'Unknown connection';
            states[Connection.ETHERNET] = 'Ethernet connection';
            states[Connection.WIFI]     = 'WiFi connection';
            states[Connection.CELL_2G]  = 'Cell 2G connection';
            states[Connection.CELL_3G]  = 'Cell 3G connection';
            states[Connection.CELL_4G]  = 'Cell 4G connection';
            states[Connection.CELL]     = 'Cell generic connection';
            states[Connection.NONE]     = 'No network connection';

            
            
            if (states[networkState] == 'Cell 3G connection'){
            alert('Connection type: ' + states[networkState]);
            alert('OMG ');
            console.log('Connection type: ' + states[networkState]);
                        
            
            
            
            
            }            else {
            
            alert('Connection type: ' + states[networkState]);
            var xml;
            
           $.ajax({
            type: "GET",
            url: "http://wohlgemuth-team.de/messe.xml",
            dataType: "xml",
            success: function(data) {
            	xml = data;

            	$('#load').fadeOut();

            	$(xml).find("messename").each(function () {
                name = $(this).attr("name");
                var datum = $(this).find("email").text();
                

                $("#list").append('<li><h3 id="name">' + name + '</h3><ul></ul></li>');

                $('#list').listview('refresh'); 
                
       			});
                
                }
                
        
        });
       
       
            }
        }
	

	
	 
</script>

  </head>

  <body onload="onLoad();">

       <div data-role="page"> 
       
       <div data-role="panel" id="mypanel">
    <!-- panel content goes here -->
</div><!-- /panel -->
       
       	<div data-role="header" data-fullscreen="true">
       	<a href="#mypanel" data-icon="home">Menu</a>
		<h1>Test</h1>
	</div><!-- /header -->

	<div data-role="content">	
		<div class="content-primary">
		
		

              <ul id="list" data-role="listview" data-theme="a" data-filter="true">
              <li id="load">Loading Data...</li>
              </ul>
              <ul id="results" data-role="listview" data-theme="a">
              </ul>
         </div>
	</div><!-- /content -->

	<div data-role="footer">
		<h4>Page Footer</h4>
	</div><!-- /footer -->
	</div> 

  </body>

</html> 